package com.cheer.ba.view.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;

import com.cheer.ba.R;
import com.cheer.ba.view.base.BaseCommAty;
import com.cheer.ba.view.fragment.MyCardGroupFrg;
import com.cheer.ba.widget.PagerSlidingTabStrip;

import butterknife.BindView;

/**
 * 我的卡券
 *
 * @author HQ
 *         created at 2017/4/24 0024 9:42
 */
public class MyCardGroupAty extends BaseCommAty {

    public static final String[] titles = {"未使用", "使用记录", "已过期"};

    //头
    @BindView(R.id.id_comm_pager_tab)
    PagerSlidingTabStrip mCircleTab;
    @BindView(R.id.id_comm_viewpager)
    ViewPager mCricleVp;

    //滑动头部适配器
    private CircleVpAdapter mCircleVpAdapter;

    @Override
    protected boolean isSupportSwipeback() {
        return false;
    }

    @Override
    public View loadView(LayoutInflater inflater, View childView) {
        return super.loadView(inflater, inflater.inflate(R.layout.aty_my_card_group, null, false));
    }

    @Override
    public void initPresenter() {
        super.initPresenter();
    }

    @Override
    public void initView() {
        setTitleText(getString(R.string.mine_free_card_group));
    }

    @Override
    public void initData() {
        mCircleVpAdapter = new CircleVpAdapter(getSupportFragmentManager());
        mCricleVp.setAdapter(mCircleVpAdapter);
        mCircleTab.setCustomLayoutParams(titles.length);
        mCircleTab.setViewPager(mCricleVp);
    }

    private class CircleVpAdapter extends FragmentPagerAdapter {
        public CircleVpAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                //未使用
                case 0:
                    return MyCardGroupFrg.newInstace(0);
                //使用记录
                case 1:
                    return MyCardGroupFrg.newInstace(1);
                //已过期
                case 2:
                    return MyCardGroupFrg.newInstace(2);
            }
            return null;
        }

        @Override
        public int getCount() {
            return titles.length;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return titles[position];
        }
    }
}
